<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="height=device-height,width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<link href="img/css/css.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/demo.Default.css" />
<style type="text/css">
.disable{
	filter: gray;
	-moz-opacity:0.3;
	opacity:0.3;
}
</style>
<script src="http://webapi.amap.com/maps?v=1.3&key=57c58c7b1f94514317df97e3a985962c"></script>
<script language="javascript" type="text/javascript" src="js/WdatePicker.js"></script>
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="js/QueryStringParser.js"></script>
<script type="text/javascript" src="js/jquery.json.min.js"></script>  
<script type="text/javascript" src="js/jsonMsg.js"></script>  
<script language="javascript">
var mapObj;
var windowsArr = [];
var marker = [];
function mapInit() {
 
    mapObj = new AMap.Map("iCenter", {
        view: new AMap.View2D({
            center:new AMap.LngLat(121.357428,31.23923),//地图中心点
            zoom:13//地图显示的缩放级别
        }),
        keyboardEnable:false
    });
    mapObj.plugin(["AMap.ToolBar"],function(){		
			toolBar = new AMap.ToolBar();
			mapObj.addControl(toolBar);		
		});
	
	//document.getElementById("keyword").onkeyup = keydown;
}
 
//输入提示
function autoSearch() {
    var keywords = document.getElementById("keyword").value;
    var cityName = document.getElementById("city").value;
    if(cityName==null || cityName.trim()==""){
    	alert("请先输入城市!");
    	return false;	
    }
    var auto;
    //加载输入提示插件
        AMap.service(["AMap.Autocomplete"], function() {
        var autoOptions = {
            city: cityName //城市，默认全国
        };
        auto = new AMap.Autocomplete(autoOptions);
        //查询成功时返回查询结果
        if ( keywords.length > 0) {
            auto.search(keywords, function(status, result){
            	autocomplete_CallBack(result);
            });
        }
        else {
            document.getElementById("result1").style.display = "none";
        }
    });
}
 
//输出输入提示结果的回调函数
function autocomplete_CallBack(data) {
    var resultStr = "";
    var tipArr = data.tips;
    if (tipArr&&tipArr.length>0) {                 
        for (var i = 0; i < tipArr.length; i++) {
            resultStr += "<div id='divid" + (i + 1) + "' onmouseover='openMarkerTipById(" + (i + 1)
                        + ",this)' onclick='selectResult(" + i + ")' onmouseout='onmouseout_MarkerStyle(" + (i + 1)
                        + ",this)' style=\"font-size: 13px;cursor:pointer;padding:5px 5px 5px 5px;\"" + "data=" + tipArr[i].adcode + ">" + tipArr[i].name + "<span style='color:#C1C1C1;'>"+ tipArr[i].district + "</span></div>";
        }
    }
    else  {
        resultStr = " π__π 亲,人家找不到结果!<br />要不试试：<br />1.请确保所有字词拼写正确<br />2.尝试不同的关键字<br />3.尝试更宽泛的关键字";
    }
    document.getElementById("result1").curSelect = -1;
    document.getElementById("result1").tipArr = tipArr;
    document.getElementById("result1").innerHTML = resultStr;
    document.getElementById("result1").style.display = "block";
}
 
//输入提示框鼠标滑过时的样式
function openMarkerTipById(pointid, thiss) {  //根据id打开搜索结果点tip 
    thiss.style.background = '#CAE1FF';
}
 
//输入提示框鼠标移出时的样式
function onmouseout_MarkerStyle(pointid, thiss) {  //鼠标移开后点样式恢复 
    thiss.style.background = "";
}
 
//从输入提示框中选择关键字并查询
function selectResult(index) {
    if(index<0){
        return;
    }
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        document.getElementById("keyword").onpropertychange = null;
        document.getElementById("keyword").onfocus = focus_callback;
    }
    //截取输入提示的关键字部分
    var text = document.getElementById("divid" + (index + 1)).innerHTML.replace(/<[^>].*?>.*<\/[^>].*?>/g,"");
	var cityCode = document.getElementById("divid" + (index + 1)).getAttribute('data');
    document.getElementById("keyword").value = text;
    document.getElementById("result1").style.display = "none";
    //根据选择的输入提示关键字查询
    mapObj.plugin(["AMap.PlaceSearch"], function() {       
        var msearch = new AMap.PlaceSearch();  //构造地点查询类
        AMap.event.addListener(msearch, "complete", placeSearch_CallBack); //查询成功时的回调函数
		msearch.setCity(cityCode);
        msearch.search(text);  //关键字查询查询
    });
}
 
//定位选择输入提示关键字
function focus_callback() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        document.getElementById("keyword").onpropertychange = autoSearch;
   }
}
 
//输出关键字查询结果的回调函数
function placeSearch_CallBack(data) {
    //清空地图上的InfoWindow和Marker
    windowsArr = [];
    marker     = [];
    mapObj.clearMap();
    var resultStr1 = "";
    var poiArr = data.poiList.pois;
    var resultCount = poiArr.length;
    for (var i = 0; i < 1; i++) {
        resultStr1 += "<div id='divid" + (i + 1) + "' onmouseover='openMarkerTipById1(" + i + ",this)' onmouseout='onmouseout_MarkerStyle(" + (i + 1) + ",this)' style=\"font-size: 12px;cursor:pointer;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;\"><table><tr><td><img src=\"http://webapi.amap.com/images/" + (i + 1) + ".png\"></td>" + "<td><h3><font color=\"#00a6ac\">名称: " + poiArr[i].name + "</font></h3>";
            resultStr1 += TipContents(poiArr[i].type, poiArr[i].address, poiArr[i].tel) + "</td></tr></table></div>";
            addmarker(i, poiArr[i]);
    }
    mapObj.setFitView();
    //document.getElementById("result").innerHTML = resultStr1;
    //document.getElementById("result").style.display = "block";
}
 
//鼠标滑过查询结果改变背景样式，根据id打开信息窗体
function openMarkerTipById1(pointid, thiss) {
    this.style.background = '#CAE1FF';
    windowsArr[pointid].open(mapObj, marker[pointid]);
}
 
//添加查询结果的marker&infowindow   
function addmarker(i, d) {
    var lngX = d.location.getLng();
    var latY = d.location.getLat();
    var markerOption = {
        map:mapObj,
        icon:"http://webapi.amap.com/images/" + (i + 1) + ".png",
        position:new AMap.LngLat(lngX, latY)
    };
    var mar = new AMap.Marker(markerOption);         
    marker.push(new AMap.LngLat(lngX, latY));
 
    var infoWindow = new AMap.InfoWindow({
        content:"<h3><font color=\"#00a6ac\">  " + (i + 1) + ". " + d.name + "</font></h3>" + TipContents(d.type, d.address, d.tel),
        size:new AMap.Size(300, 0),
        autoMove:true, 
        offset:new AMap.Pixel(0,-30)
    });
    windowsArr.push(infoWindow);
    var aa = function (e) {infoWindow.open(mapObj, mar.getPosition());};
    AMap.event.addListener(mar, "click", aa);
}
 
//infowindow显示内容
function TipContents(type, address, tel) {  //窗体内容
    if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") {
        type = "暂无";
    }
    if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") {
        address = "暂无";
    }
    if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") {
        tel = "暂无";
    }
    var str = "  地址：" + address + "<br />  电话：" + tel + " <br />  类型：" + type;
    return str;
}
function keydown(event){
    var key = (event||window.event).keyCode;
    var result = document.getElementById("result1")
    var cur = result.curSelect;
    if(key===40){//down
        if(cur + 1 < result.childNodes.length){
            if(result.childNodes[cur]){
                result.childNodes[cur].style.background='';
            }
            result.curSelect=cur+1;
            result.childNodes[cur+1].style.background='#CAE1FF';
            document.getElementById("keyword").value = result.tipArr[cur+1].name;
        }
    }else if(key===38){//up
        if(cur-1>=0){
            if(result.childNodes[cur]){
                result.childNodes[cur].style.background='';
            }
            result.curSelect=cur-1;
            result.childNodes[cur-1].style.background='#CAE1FF';
            document.getElementById("keyword").value = result.tipArr[cur-1].name;
        }
    }else if(key === 13){
        var res = document.getElementById("result1");
		if(res && res['curSelect'] !== -1){
			selectResult(document.getElementById("result1").curSelect);
		}
    }else{
        autoSearch();
    }
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {

        xScroll = window.innerWidth + window.scrollMaxX;

        yScroll = window.innerHeight + window.scrollMaxY;

    } else {

        if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac    

            xScroll = document.body.scrollWidth;

            yScroll = document.body.scrollHeight;

        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari    

            xScroll = document.body.offsetWidth;

            yScroll = document.body.offsetHeight;

        }

    }

    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer    

        if (document.documentElement.clientWidth) {

            windowWidth = document.documentElement.clientWidth;

        } else {

            windowWidth = self.innerWidth;

        }

        windowHeight = self.innerHeight;

    } else {

        if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode    

            windowWidth = document.documentElement.clientWidth;

            windowHeight = document.documentElement.clientHeight;

        } else {

            if (document.body) { // other Explorers    

                windowWidth = document.body.clientWidth;

                windowHeight = document.body.clientHeight;

            }

        }

    }       

    // for small pages with total height less then height of the viewport    

    if (yScroll < windowHeight) {

        pageHeight = windowHeight;

    } else {

        pageHeight = yScroll;

    }    

    // for small pages with total width less then width of the viewport    

    if (xScroll < windowWidth) {

        pageWidth = xScroll;

    } else {

        pageWidth = windowWidth;

    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

    return arrayPageSize;

}
</script>
<title>查看旅程-领队</title>
</head>

<body onload="mapInit();">
<div class="keep" id="pop" style="display: none;"><img src="img/Share_popup_text.png"></div>
<div class="tool_bar">
     <img src="" class="user_pic_tool" width="50px;" height="50px;" id="userimage" style="display: none;"/>
     <div class="list_text_tool">
           <div class="list_title_tool" id="title"></div>
           <div class="list_dis_tool"><i class="iconfont tool_ico">&#xe610;</i><p id="city"></p></div>
           <div class="list_user_status">
                <p class="user_tool" id="num"><i class="iconfont tool_ico">&#xe609;</i></p>
                <p class="status_tool" id="validDate"></p>
           </div>
      </div>
</div>
<div style="width:99%;height:250px" id="iCenter"></div>
<script type="text/javascript">
	document.getElementById("iCenter").style.height=(getPageSize()[1]-80-102)+"px";
</script>
<div class="bottom_user_list">
     <div class="user_list" id="members">
          <!--div class="user_group highlight">
               <p><img src="img/user_pic.png" width="30px" height="30px"></p>
               <p class="user_group_name">张三</p>
          </div>
          <div class="user_group">
               <p><img src="img/user_pic.png" width="30px" height="30px"></p>
               <p class="user_group_name">张三</p>
          </div-->
          <div class="more_arrow"><i class="iconfont">&#xe611;</i></div>
     </div>
     <div class="bottom_btn">
         <div class="btn_4"><p class="ico_group" onclick="updateTripStatus('Active')" style="cursor:pointer;"><i class="iconfont img">&#xe60b;</i><font id="startMsg">启程</font></p></div>
         <div class="btn_4 line_left" id="editMenu" style="cursor:pointer;"><p class="ico_group"><i class="iconfont img">&#xe608;</i>编辑</p></div>
         <div class="btn_4 line_left"><p class="ico_group" onclick="updateTripStatus('Terminate')" style="cursor:pointer;"><i class="iconfont img">&#xe606;</i>结束</p></div>
         <div class="btn_4 line_left"><p class="ico_group"><button id="onMenuShareAppMessage" class="ico_group_btn" style="cursor:pointer;"><i class="iconfont img">&#xe609;</i>邀请</button></p></div>
     </div>
</div>

</body>
</html>

<script type="text/javascript">
var latLon = "";
var openId = queryString.getParam("openid");
var tripId = queryString.getParam("tripid");
var isActive = queryString.getParam("isActive");
var ownerName = "";
var imageURL = "";
if(tripId.indexOf("#")>-1){
  tripId = tripId.replace("#","");
}
$(document).ready(function(){
    
  if(openId==null || openId=="" || tripId==null || tripId==""){
    alert("参数错误...");
    window.location.href="add_trip.html?openid="+ openId;
    return false; 
  }else{
      //retrieveFriends()
      setMenu(openId, tripId);
      retrieveTrip(tripId);
      if(isActive==1){
      	$("#startMsg").html("进入");
    	}
  }
  
});

function updateTripStatus(stats){
		if(isActive==1 && stats=='Active'){
				window.location.href="trip_voice.html?openid="+openId+"&tripid="+tripId;
				return false;
		}
	
		var dataStr = {
      "TripID" : tripId,
      "TripStatus" : stats 
    }; 
    var bodyStr = popBody('EditTripStatus',dataStr);
    var request = popRequest('EditTripStatus',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  

    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
        	if(stats=='Active'){
        			window.location.href="trip_voice.html?openid="+openId+"&tripid="+tripId;
        	}else{
        			window.location.href="trip_list.html?openid="+openId;	
        	}
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}

function setMenu(openId, tripId){
    $("#editMenu").click(function(){
            window.location.href="edit_trip.html?isActive="+isActive+"&openid="+openId+"&tripid="+tripId;
      });
}

function retrieveTrip(tripId){
    var dataStr = {
      "TripID" : tripId 
    }; 
    var bodyStr = popBody('TripDetail',dataStr);
    var request = popRequest('TripDetail',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  

    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
          //$("#tripOwner").html(data.portalResp.Data.MemberStatus[0].Nickname); 
          
          $("#city").html("目的地："+ data.portalResp.Data.Destination.Name);
          $("#num").html("<i class=\"iconfont tool_ico\">&#xe609;</i>参与人数："+ data.portalResp.Data.MemberStatus.length + "人");
          $("#validDate").html(data.portalResp.Data.ValidDate); 
//          if(data.portalResp.Data.MemberStatus.length > 0){
//            $("#userimage").attr("src",data.portalResp.Data.MemberStatus[0].ImageURL);
//          }

          var tripMember = "";
          $.each(data.portalResp.Data.MemberStatus, function(index){  
                if(data.portalResp.Data.TripLeader==data.portalResp.Data.MemberStatus[index].OpenID){
	                tripMember += "<div class=\"user_group highlight\"><p><img src=\""+data.portalResp.Data.MemberStatus[index].ImageURL+"\" ";
	                tripMember += "width=\"40px\" height=\"40px\"></p><p class=\"user_group_name\">"+data.portalResp.Data.MemberStatus[index].Nickname+"</p></div>";
	                $("#userimage").attr("src",data.portalResp.Data.MemberStatus[index].ImageURL);
	                document.getElementById("userimage").style.display="";
	                $("#title").html(data.portalResp.Data.MemberStatus[index].Nickname+"创建的"+data.portalResp.Data.Title);
	                ownerName  = data.portalResp.Data.MemberStatus[index].Nickname;
	                imageURL = data.portalResp.Data.MemberStatus[index].ImageURL;
              	}else{
              		if(data.portalResp.Data.MemberStatus[index].TripMemberStatus=="-1"){
              			tripMember += "<div class=\"user_group\"><p><img class=\"disable\" src=\""+data.portalResp.Data.MemberStatus[index].ImageURL+"\" ";
              		}else{
              			tripMember += "<div class=\"user_group\"><p><img src=\""+data.portalResp.Data.MemberStatus[index].ImageURL+"\" ";
              		}
	                tripMember += "width=\"40px\" height=\"40px\"></p><p class=\"user_group_name\">"+data.portalResp.Data.MemberStatus[index].Nickname+"</p></div>";
              	}
            }); 

          $("#members").html(tripMember);
          //var pos = new AMap.LngLat(data.portalResp.Data.Destination.Loc.Longitude,data.portalResp.Data.Destination.Loc.Latitude);
          //mapObj.setCenter(pos);

          var marker = new AMap.Marker({                
                icon: "http://webapi.amap.com/images/1.png",
                position:new AMap.LngLat(data.portalResp.Data.Destination.Loc.Longitude/1000000,
                    data.portalResp.Data.Destination.Loc.Latitude/1000000)
            });

          marker.setMap(mapObj);  //在地图上添加点
          //mapObj.setFitView();
          mapObj.setZoomAndCenter(15, new AMap.LngLat(data.portalResp.Data.Destination.Loc.Longitude/1000000,
                  data.portalResp.Data.Destination.Loc.Latitude/1000000));
          
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}

function addMarker(){
    var LngLatX = document.getElementById("lnglatX").value; //获取Lng值
            var LngLatY = document.getElementById("lnglatY").value; //获取Lat值
            marker = new AMap.Marker({                
                icon: "http://webapi.amap.com/images/1.png",
                position:new AMap.LngLat(LngLatX,LngLatY)
            });
        
            marker.setMap(map);  //在地图上添加点
            map.setFitView(); //调整到合理视野
        }

function retrieveFriends(){
    var dataStr = {}; 
    var bodyStr = popBody('ListFriends',dataStr);
    var request = popRequest('ListFriends',openId,bodyStr);
    //调用了jquery.json 库  
    var encoded = $.toJSON( request );  
    var jsonStr = encoded;  

    $.ajax({  
      url : actionStr,  
      type : 'POST',  
      data : jsonStr,  
      dataType : 'json',  
      contentType : 'application/json',  
      success : function(data, status, xhr) {  
      //         Do Anything After get Return data  
                
                //alert(data.portalResp.FuncID);
                //$("#friends").append("<option value='1'>张三</option>");  
      },  
      Error : function(xhr, error, exception) {  
          // handle the error.    
          alert(exception.toString());  
      }  
    });  
}

</script>


<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
	var pageURL = location.href.split('#')[0];
	//alert(pageURL);
	//alert(pageURL.substring(0,pageURL.lastIndexOf("/")));
	$(document).ready(function(){
  	

		var dataStr = {
			PageURL: 	pageURL
		};	
		var bodyStr = popBody('JSSignature',dataStr);
		var request = popRequest('JSSignature',openId,bodyStr);
		//调用了jquery.json 库  
		var encoded = $.toJSON( request );  
		var jsonStr = encoded;  

		$.ajax({  
		url : actionStr,  
		type : 'POST',  
		data : jsonStr,  
		dataType : 'json',  
		contentType : 'application/json',  
		success : function(data, status, xhr) {  
		//         Do Anything After get Return data  
		        var timestamp = data.portalResp.Data.timestamp;
		        var noncestr = data.portalResp.Data.noncestr;
		        var signature = data.portalResp.Data.signature;
		        var appId = data.portalResp.Data.appId;  
		        
		         /*
					   * 注意：
					   * 1. 所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
					   * 2. 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
					   * 3. 常见问题及完整 JS-SDK 文档地址：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
					   *
					   * 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决，如仍未能解决可通过以下渠道反馈：
					   * 邮箱地址：weixin-open@qq.com
					   * 邮件主题：【微信JS-SDK反馈】具体问题
					   * 邮件内容说明：用简明的语言描述问题所在，并交代清楚遇到该问题的场景，可附上截屏图片，微信团队会尽快处理你的反馈。
					   */
					  wx.config({
					      debug: false,
					      appId: appId,
					      timestamp: timestamp,
					      nonceStr: noncestr,
					      signature: signature,
					      jsApiList: [
					      	'hideOptionMenu',
					      	'showOptionMenu',
					        'onMenuShareAppMessage'
					      ]
					  });
					
					wx.ready(function () {
						wx.hideOptionMenu();
					  // 2. 分享接口
					  // 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
					  document.querySelector('#onMenuShareAppMessage').onclick = function () {
					  	document.getElementById("pop").style.display="";
					  	wx.showOptionMenu();
					    wx.onMenuShareAppMessage({
					      title: '旅程邀请',
					      desc: '您的好友'+ownerName+'邀请您加入公众号--结伴旅行。同行的还有高帅富、白富美，您还在等什么呢。',
					      link: "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURIComponent(pageURL.substring(0,pageURL.lastIndexOf("/"))+"/oauthServlet?type=2&openid="+openId+"&tripid="+tripId)+"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect",
					      imgUrl: imageURL,
					      trigger: function (res) {
					        //alert('用户点击发送给朋友');
					      },
					      success: function (res) {
					      	document.getElementById("pop").style.display="none";
					        alert('已邀请');
					      },
					      cancel: function (res) {
					        alert('已取消');
					      },
					      fail: function (res) {
					        alert(JSON.stringify(res));
					      }
					    });
					    //alert('注册获取“发送给朋友”状态事件');
					  };
					
					  var shareData = {
					    title: '微信JS-SDK Demo',
					    desc: '微信JS-SDK,帮助第三方为用户提供更优质的移动web服务',
					    link: 'http://demo.open.weixin.qq.com/jssdk/',
					    imgUrl: 'http://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRt8Qia4lv7k3M9J1SKqKCImxJCt7j9rHYicKDI45jRPBxdzdyREWnk0ia0N5TMnMfth7SdxtzMvVgXg/0'
					  };
					  wx.onMenuShareAppMessage(shareData);

					});
				
					wx.error(function (res) {
					  alert(res.errMsg);
					});
		},  
		Error : function(xhr, error, exception) {  
		    // handle the error.    
		    alert(exception.toString());  
		}  
		});  
	

 
});
</script>